package com.mall.web.controller.product;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.product.domain.biz.ProBrandRecommendedBiz;
import com.mall.product.domain.entity.ProBrand;
import com.mall.product.domain.entity.ProBrandRecommended;
import com.mall.product.service.ProBrandRecommendedService;
import com.mall.product.service.ProBrandService;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌推荐Controller
 *
 * @author zhonglin
 * @date 2020-05-19
 */
@Controller
@RequestMapping("/product/brandRecommended")
public class ProBrandRecommendedController
    extends BaseController {

  private String prefix = "product/brandRecommended";

  @Autowired
  private ProBrandRecommendedService proBrandRecommendedService;
  @Autowired
  private ProBrandService proBrandService;

  @RequiresPermissions("product:brandRecommended:view")
  @GetMapping()
  public String brandRecommended(ModelMap mmap) {

    List<ProBrand> brands = proBrandService.selectBrandAll();
    mmap.put("brands", brands);
    return prefix + "/brandRecommended";
  }

  /**
   * 查询品牌推荐列表
   */
  @RequiresPermissions("product:brandRecommended:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(ProBrandRecommended proBrandRecommended) {

    startPage();
    List<ProBrandRecommendedBiz> list = proBrandRecommendedService.selectProBrandRecommendedList(proBrandRecommended);
    return getDataTable(list);
  }

  /**
   * 导出品牌推荐列表
   */
  @RequiresPermissions("product:brandRecommended:export")
  @Log(title = "品牌推荐", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(ProBrandRecommended proBrandRecommended) {

    List<ProBrandRecommendedBiz>      list = proBrandRecommendedService.selectProBrandRecommendedList(proBrandRecommended);
    ExcelUtil<ProBrandRecommendedBiz> util = new ExcelUtil<ProBrandRecommendedBiz>(ProBrandRecommendedBiz.class);
    return util.exportExcel(list, "brandRecommended");
  }

  /**
   * 新增品牌推荐
   */
  @GetMapping("/add")
  public String add(ModelMap mmap) {
    List<ProBrand> brands = proBrandService.selectBrandAll();
    mmap.put("brands", brands);
    return prefix + "/add";
  }

  /**
   * 新增保存品牌推荐
   */
  @RequiresPermissions("product:brandRecommended:add")
  @Log(title = "品牌推荐", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(ProBrandRecommended proBrandRecommended) {

    return toAjax(proBrandRecommendedService.insertProBrandRecommended(proBrandRecommended));
  }

  /**
   * 修改品牌推荐
   */
  @GetMapping("/edit/{brandRecommendedId}")
  public String edit(@PathVariable("brandRecommendedId") Long brandRecommendedId,
                     ModelMap mmap) {

    ProBrandRecommendedBiz proBrandRecommended = proBrandRecommendedService.selectProBrandRecommendedById(brandRecommendedId);
    mmap.put("proBrandRecommended", proBrandRecommended);
    return prefix + "/edit";
  }

  /**
   * 修改保存品牌推荐
   */
  @RequiresPermissions("product:brandRecommended:edit")
  @Log(title = "品牌推荐", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(ProBrandRecommended proBrandRecommended) {

    return toAjax(proBrandRecommendedService.updateProBrandRecommended(proBrandRecommended));
  }

  /**
   * 删除品牌推荐
   */
  @RequiresPermissions("product:brandRecommended:remove")
  @Log(title = "品牌推荐", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {

    return toAjax(proBrandRecommendedService.deleteProBrandRecommendedByIds(ids));
  }

}
